<?php 
namespace App\Services\Admin;

use App\Facades\Infra\Admin\DoctorManage;
use App\Facades\Utils\QiniuFileManager;

class DoctorService{

	public function createDoctorInfo($data){

		$openid = DoctorManage::getDoctor($data['wechat_doctor_id'])->openid;

		$data['ticket'] = $this->generateQRCode($openid);

		$data['headimg'] = $this->getHeadImgUrl($data['headimg']);
		
		DoctorManage::createDoctorInfo($data);
	}

	public function updateDoctorInfo($data){
		if($data['headimg'] != null && $data['headimg'] != ""){
			$data['headimg'] = $this->getHeadImgUrl($data['headimg']);
		}

		$id = $data['id'];

		DoctorManage::updateDoctorInfo($id,$data);
	}

	public function getHeadImgUrl($key){
		return QiniuFileManager::getFileUrl($key,'public');
	}

	public function generateQRCode($openid){

		$wechat = app('wechat');

		$qrcode = $wechat->qrcode;

		$sceneValue = $openid;

		$result = $qrcode->forever($sceneValue);

		$ticket = $result->ticket;

		return $ticket;
	}
}